/**
 * @author KujoMiva
 * @name Over.ts
 * @desc 截图页面
 * @time 2020年02月11日 22:37:49 星期二
 */
class Over extends egret.DisplayObjectContainer {
  public constructor() {
    super()
    this.once(egret.Event.ADDED_TO_STAGE, this.init, this)
  }

  private init() {
    this.creaetBg()
    this.createUser()
    this.submit()
    Utils.createScale(this, this.parent)
  }

  private submit() {
    const formData = {
      avatar: ParamsPool.USER_AVATAR,
      text: ParamsPool.CHECK_NUM,
      path: ParamsPool.PATH_NUM
    }
    console.log(formData)
    $.post('http://39.104.181.160:7489/H5', formData).then(res => {
      console.log(res)
    })
  }

  private creaetBg() {
    const bg = Utils.createBitmapByName('bg_cys2_png')
    this.addChild(bg)
  }

  private async createUser() {
    const container = new egret.Sprite()
    const btn = Utils.createBitmapByName(`btn_${ParamsPool.CHECK_NUM}_png`)
    const buffer = btn.width / btn.height
    btn.height = 380
    btn.width = btn.height * buffer
    container.addChild(btn)

    const avatar_mask_item = Utils.createBitmapByName('item_avatar_2_png')
    let avatar: any = await Utils.createBitmpByUrl(ParamsPool.USER_AVATAR)
    try {
      avatar = await Utils.createBitmpByUrl(ParamsPool.USER_AVATAR)
    } catch (error) {
      alert('获取头像失败,已启用备用头像')
      avatar = await Utils.createBitmpByUrl('https://thirdqq.qlogo.cn/qqapp/1104455702/4AFC34E4A90E0BB5B52FE0E374B6E249/100?imageView2/1/w/80/h/80')
    }
    const avatar_mask = new egret.Shape()
    avatar_mask.graphics.beginFill(0, 1)
    avatar_mask.graphics.drawCircle(avatar_mask_item.width / 2, avatar_mask_item.width / 2, avatar_mask_item.width / 2)
    avatar_mask.graphics.endFill()


    container.addChild(avatar_mask)
    avatar_mask.x = 233
    avatar_mask.y = -40
    Utils.dragGetPatn(avatar_mask, container)
    container.addChild(avatar)
    avatar.width = avatar_mask_item.width
    avatar.height = avatar_mask_item.width
    avatar.x = 233
    avatar.y = -40
    avatar.mask = avatar_mask

    this.addChild(container)
    container.x = 115
    container.y = 1720

    Utils.shareImage(this)
  }
}